% Test the speed of MPC.m
tic
W = [0.45;0.35;0.25;0.15;0.1];

feedback.alpha = rand(20,1);
feedback.beta = rand(20,1);
feedback.h = 150;
feedback.rho = 0.98;
feedback.t = 1000;

settings.D_set = 0.985;
settings.Fact_D = 0;
settings.R2_set = 50;
settings.Fact_r2 = 1.0;
settings.Ht_set = 800;
settings.Fact_H = 1.0;
settings.P = 5;
settings.m = 20;
settings.dt = 5;
settings.lb = 0.1;
settings.ub = 0.45;
settings.rt_dep = 0.1;
settings.T_end = 3000;
settings.ControllerTypeID = 101;
%%
% tic;
% for j = 1:1000
%     [W,Fval] = MPC(feedback,settings,W(1));
% end
% toc;

profile on
for j = 1:100
    [W,Fval] = MPC1xx(feedback,settings,W(1));
end
profile viewer
p = profile('info');
profsave(p,'profile_results_MPC_C');
profile clear
for j = 1:100
    [Wm,Fvalm] = MPC1xx(feedback,settings,W(1));
end
profile viewer
pm = profile('info');
profsave(p,'profile_results_MPC_M');

% tic
% for i = 1:1000
%     f1(i) = objfun(W,feedback,settings);
% end
% t1 = toc
% fprintf(1,'\n Matlab version\n');
% tic
% for i = 1:100
%     f0(i) = objfun_m(W,feedback,settings);
% end
% t0 = toc
    